package airthmetic.exercise.sort.cmp;


// 冒泡排序 此题部分测试用例回超时
public class _912_排序数组_Bubble2 {
    public int[] sortArray(int[] nums) {
        if(nums == null || nums.length < 2){
            return nums;
        }
        int n = nums.length;
        for(int i=0; i<n; i++){
            for(int j=1; j<n; j++){
                if (nums[j-1] > nums[j]){
                    swap(nums,j-1,j);
                }
            }
        }

        return nums;
    }

    public void swap(int[] nums, int i, int j){
        if(i == j){
            return;
        }
        nums[i] ^= nums[j];
        nums[j] ^= nums[i];
        nums[i] ^= nums[j];
    }
}
